classdef ctrTuning <tuning
    
    properties
        units = '';
        calcMethod
        tuningParams
    end
    properties(Transient = true)
        sampleTuning
        sampleRange
    end
    methods
        function s = ctrTuning(calcMethod,tuningParams,type)
            if ~exist('type','var')||isempty(type)
                type = 'ctrTuning';
            end
            s = s@tuning(type);
            if ischar(calcMethod)
                ok = false;
                switch calcMethod
                    case 'sigmoid'
                        if all(ismember(fieldnames(tuningParams),{'c50','n'}))...
                                && isnumeric(tuningParams.c50) && isnumeric(tuningParams.n)
                            ok = true;
                        end
                end
                if ~ok
                    error('ctrTuning:inappropriateInput','calcMethod is wrong or params do not match calcMethod');
                end
                s.calcMethod = calcMethod;
                s.tuningParams = tuningParams;
            else
                error('ctrTuning:wrongType','type needs to be a char');
            end
        end
        
        function out = sample(s,stim)
            switch s.calcMethod
                case 'sigmoid'
                    CTR = getContrast(stim);
                    out = (CTR^s.tuningParams.n)/(CTR^s.tuningParams.n+s.tuningParams.c50^s.tuningParams.n);
            end
        end
    end
end